<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <link rel="stylesheet" href="layui/css/layui.css">
    <link rel="stylesheet" href="css/common.css">
    <style>
        html{
            min-width: 1010px;
            min-height: 645px;
        }
    </style>
</head>
<body>
<div id="bg">
    <div id="systemImg"></div>
    <div id="loginBox">
        <form id="loginForm" class="layui-form" lay-filter="loginForm">
            <div id="formHeader">
                <div id="formHeaderText">账号登录</div>
            </div>
            <div id="formContent">
                <div class="inputBox">
                    <img src="img/phone.png" alt="">
                    <input type="text" id="username" name="username" class="input" placeholder="用户名" maxlength="15" value="">
                </div>
                <div class="inputBox">
                    <img src="img/shield.png" alt="">
                    <input type="password" id="password" name="password" class="input" placeholder="密码" maxlength="15" value="">
                </div>
                <div id="loginBtnBox">
                    <button type="button" id="loginBtn">登&nbsp;&nbsp;录</button>
                </div>
            </div>
        </form>
    </div>
    <div id="copyRight">
       ©2020四川恒泰佳祥实业有限公司&nbsp;&nbsp;&nbsp;备案号：蜀ICP备19019975号-1
    </div>
</div>
<script src="layui/layui.js"></script>
<script src="js/common.js"></script>
<script>
    layui.use(['form','jquery'],function () {
        var form = layui.form,
            $ = layui.jquery;

        $("#loginBtn").on("click",function () {
            var formData = form.val("loginForm");

            var username = formData.username,
                password = formData.password;

            if(!username){
                layer.msg("请输入手机号/用户名");
            }
            else if(!password){
                layer.msg("请输入密码");
            }
            else{
                $.ajax({
                    url: api + "/user/login",
                    data: {
                        userName: username,
                        passWord: password
                    },
                    type: 'post',
                    dataType: 'json',
                    success: function (res) {
                        layer.msg(res.message);
                        if(res.code === 1004){
                            //max-age是以秒为单位
                            // window.location.href = `pages/carInfo.html?name=${res.data.name}&company_id=${res.data.companyId}`;
                            window.location.href = `pages/carInfo.html?name=${res.data.name}&token=${res.data.token}`;
                        }
                    }
                })
            }
        });
    });
</script>
</body>
</html>